import React from 'react';
import {connect} from 'react-redux';
import Input from './input'
import Message from './message'
import Button from './button'

/**
 * 定义action类型
 * @type {string}
 */
const INCREASE_NUMBER = 'INCREASE_NUMBER';
const SHOW_NUMBER = 'SHOW_NUMBER';
const SET_STEP = 'SET_STEP';

/**
 * 定义创建action的函数
 * @returns {{type: string, number: *}}
 */
var increaseNumber = function () {
    return {
        type:INCREASE_NUMBER
    }
}

/**
 * 定义创建action的函数
 * @returns {{type: string, number: *}}
 */
var setStep = function (step = 1) {
    return {
        type:SET_STEP,
        step:step
    }
}

/**
 * 定义reducer
 * @param state
 * @param action
 * @returns {*}
 */
var reducer = function (state,action) {
    switch (action.type){
        case INCREASE_NUMBER:
            return Object.assign({},state,{
                number:Number(state.number) + Number(state.step)
            })
            break;
        case SHOW_NUMBER:
            return Object.assign({},state,{
                number:state.number
            })
            break;
        case SET_STEP:
            return Object.assign({},state,{
                step:action.step
            })
            break;
        default:
            return state;
    }
}

export {reducer,increaseNumber,setStep,SHOW_NUMBER,INCREASE_NUMBER};

class App extends React.Component{
    render(){
        return <section>
            <Message />
            <Input />
            <Button />
        </section>
    }
}

export default connect(
    function (state) {
        return state;
    },
    function (dispatch) {
        return {}
})(App)

//export default App;